package cn.action;

import java.util.List;

import cn.biz.BrandBiz;
import cn.entity.Brand;

import com.opensymphony.xwork2.Action;

public class BrandAction implements Action {
	private BrandBiz brandBiz;
	private Brand brand;
	private List<Brand> Blist;
	private String resultStr;
	
	public BrandBiz getBrandBiz() {
		return brandBiz;
	}

	public void setBrandBiz(BrandBiz brandBiz) {
		this.brandBiz = brandBiz;
	}

	public Brand getBrand() {
		return brand;
	}

	public void setBrand(Brand brand) {
		this.brand = brand;
	}

	public List<Brand> getBlist() {
		return Blist;
	}

	public void setBlist(List<Brand> blist) {
		Blist = blist;
	}

	public String getResultStr() {
		return resultStr;
	}

	public void setResultStr(String resultStr) {
		this.resultStr = resultStr;
	}

	//后台显示全部品牌
	public String brandShow() {
		Blist = brandBiz.getAll();
		return SUCCESS;
	}
	
	//跳转到新增品牌页面
	public String brandAdd() {
		brand = new Brand();
		return SUCCESS;
	}
	
	//跳转到编辑品牌页面
	public String brandView() {
		Integer id = brand.getId();
		brand = brandBiz.getBrandById(id);
		return SUCCESS;
	}
	
	//保存编辑品牌信息
	public String brandEdit() {
		try {
			brandBiz.insertOrUpdate(brand);
			resultStr = "{\"flag\":\"success\"}";
		} catch (Exception e) {
			e.printStackTrace();
			resultStr = "{\"flag\":\"error\"}";
		}
		return SUCCESS;
	}
	
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
